Sort the wine lists in the API #138
Merged
+581
−47
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #128
What
User.winesgets asortargument and an optionalminRating:sort: WineListSort = NEWEST:NEWEST,OWN_RATING,COMMUNITY_RATING,NAMEminRating: Float(0–5): only wines with at least that shared rating.totalCountfollows itNo frontend changes. The list pages keep using the default order until #12.
How
backend/src/lists/list-query.ts, with a fixedORDER BYper sort, likewine-query.ts. Nothing from the request reaches the SQL.user_wine.id DESC, so ties are stable (newest added first).NEWESTkeeps the old id cursor, so a frontend that is already deployed keeps working.BAD_USER_INPUT.OWN_RATINGuses the review of the list's owner, never the session. Safe for public profiles (Product-page using Mock-data #14).Tests
list-query.test.ts(no database): the SQL for each order,minRatingand its limits, and cursor round trips and rejected cursors.lists-api.db.test.ts: each order one wine per page and all at once, with ties and wines without ratings,minRatingwithtotalCount, removal while paging, and a cursor from another order.docs/api.md.Docs
docs/api.md: new section «Sorting and filtering a list», with an example query, the reasons for the choices, a known limit, and a note for #129 (keyArgs).Review notes
Touches only backend and
docs/api.md. No overlap with PR 120 (#120 changes a different part ofapi.md).